<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>资讯中心 - 家政服务平台</title>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        .article-card {
            transition: transform 0.3s;
            margin-bottom: 20px;
            height: 100%;
        }
        
        .article-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        
        .article-img {
            height: 200px;
            object-fit: cover;
        }
        
        .category-badge {
            position: absolute;
            top: 10px;
            right: 10px;
        }
        
        .article-meta {
            font-size: 0.85rem;
            color: #6c757d;
        }
        
        .category-nav {
            overflow-x: auto;
            white-space: nowrap;
            padding: 10px 0;
        }
        
        .category-nav .nav-link {
            display: inline-block;
            margin-right: 10px;
        }
        
        .category-nav .nav-link.active {
            font-weight: bold;
            color: #007bff;
            border-bottom: 2px solid #007bff;
        }
    </style>
</head>

<body>
    <!-- 引入导航栏 -->
    <div th:replace="front/common/header :: header"></div>

    <div class="container mt-4">
        <div class="row">
            <div class="col-12">
                <h2 class="mb-4">资讯中心</h2>

                <!-- 分类导航 -->
                <div class="category-nav mb-4">
                    <a class="nav-link" th:classappend="${categoryId == null ? 'active' : ''}" th:href="@{/articles}">全部</a>
                    <a class="nav-link" th:each="category : ${categories}" th:classappend="${categoryId != null && categoryId == category.id ? 'active' : ''}" th:href="@{/articles(categoryId=${category.id})}" th:text="${category.name}"></a>
                </div>

                <!-- 文章列表 -->
                <div class="row">
                    <div class="col-md-4" th:each="article : ${page.records}">
                        <div class="card article-card">
                            <div class="position-relative">
                                <img th:src="${article.coverImage != null ? article.coverImage : '/img/default-article.jpg'}" class="card-img-top article-img" alt="文章封面">
                                <span class="badge bg-primary category-badge" th:text="${article.categoryName}"></span>
                            </div>
                            <div class="card-body d-flex flex-column">
                                <h5 class="card-title">
                                    <a th:href="@{/articles/{id}(id=${article.id})}" class="text-decoration-none text-dark" th:text="${article.title}"></a>
                                </h5>
                                <p class="card-text text-truncate" th:text="${article.summary}"></p>
                                <div class="article-meta mt-auto">
                                    <span><i class="bi bi-person"></i> <span th:text="${article.author}"></span></span>
                                    <span class="ms-3"><i class="bi bi-eye"></i> <span th:text="${article.viewCount}"></span></span>
                                    <span class="ms-3"><i class="bi bi-calendar"></i> <span th:text="${#dates.format(article.createdAt, 'yyyy-MM-dd')}"></span></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 分页 -->
                <div th:if="${page.total > 0}" class="d-flex justify-content-center mt-4">
                    <nav aria-label="Page navigation">
                        <ul class="pagination">
                            <li class="page-item" th:classappend="${page.current == 1 ? 'disabled' : ''}">
                                <a class="page-link" th:href="@{/articles(page=${page.current - 1}, categoryId=${categoryId})}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                            <li class="page-item" th:each="i : ${#numbers.sequence(1, page.pages)}" th:classappend="${page.current == i ? 'active' : ''}">
                                <a class="page-link" th:href="@{/articles(page=${i}, categoryId=${categoryId})}" th:text="${i}"></a>
                            </li>
                            <li class="page-item" th:classappend="${page.current == page.pages ? 'disabled' : ''}">
                                <a class="page-link" th:href="@{/articles(page=${page.current + 1}, categoryId=${categoryId})}" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        </ul>
                    </nav>
                </div>

                <!-- 无数据提示 -->
                <div th:if="${page.total == 0}" class="text-center py-5">
                    <p class="text-muted">暂无相关文章</p>
                </div>
            </div>
        </div>
    </div>

    <!-- 引入页脚 -->
    <div th:replace="front/common/footer :: footer"></div>

    <script th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/js/bootstrap.bundle.min.js}"></script>
</body>

</html>